//
//  MainTabBarController.swift
//  amicool
//
//  Created by 方君竹 on 2017/6/12.
//  Copyright © 2017年 fjz. All rights reserved.
//

import UIKit

class MainTabbarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //从故事版中取得视频主页对应的导航控制器即可
        let videoStoryboard = UIStoryboard(name: "Video", bundle: nil)
        let videoNavController = videoStoryboard.instantiateViewController(withIdentifier: "videoNav")//在videostroyboard里面给它命名的id
        let meStoryBoard = UIStoryboard(name: "me", bundle: nil)
        let me = meStoryBoard.instantiateViewController(withIdentifier: "Me")
        let coursewareNav = UINavigationController(rootViewController: CoursewareController())
        
        let articleNav = UINavigationController(rootViewController: articleController())
        
        self.viewControllers = [videoNavController,coursewareNav,articleNav,me]   //完成与标签控制器的关联
        
        //调用meviewcontroller
       // let me = MeViewController()
        
        let tabBarItemTieles:[String] = ["视频","课程","文章","我"]
        
        let tabBarItemImages:[String] = ["video","tware","article","me"]
        
        //设置tabBar
        let tabBar = self.tabBar
        self.tabBar.frame = CGRect(x: tabBar.frame.minX, y:tabBar.frame.minY,width: tabBar.frame.width, height:45)//仅设置高度，横纵坐标保持不变
        
        var index = 0
        //完成标签条内每一项的设置
        for item in self.tabBar.items!{
            //设置标题
            item.title = tabBarItemTieles[index]
            //设置图标
            let selectedImage = UIImage(named: String(format: "%@.png", tabBarItemImages[index]))?.scaleImageToSize(CGSize(width: 25, height: 25))//缩放图标尺寸，详细见extension.swift
            
            let unselsectedImage = UIImage(named: String(format: "%@-2.png", tabBarItemImages[index]))?.scaleImageToSize(CGSize(width: 25, height: 25))
            item.image = selectedImage
            item.selectedImage = unselsectedImage
            //按下与未按下，不同状态下的图标显示
            
            index += 1
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
